import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { DelDataButton, TAPMateButton, TestDetailsButton } from '../Common/options'
import { BeamsStandardData } from '../Common/Conversion'
import { Fragment } from 'react'

export const LabTension = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const beamUuid = await BeamsStandardData()
    let data = {
        type: '梁场管理',
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}GroupData`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        hideInSearch: true,
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'componentId',
                title: '梁识别码',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 150,
                hideInTable: true,
            },
            {
                dataIndex: 'organizationUuid',
                title: '组织机构',
                valueType: 'select',
                valueEnum: ClientData.organization,
                width: 150,
                rules: true,
            },
            {
                dataIndex: 'componentParts',
                title: '梁号',
                valueType: 'input',
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'tensioningDate',
                title: '张拉时间',
                valueType: 'input',
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'steelBeamNo',
                title: '钢束编号',
                valueType: 'input',
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'tensioningSection',
                title: '张拉断面',
                valueType: 'input',
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'beamUuid',
                title: '匹配桥梁',
                valueType: 'select',
                valueEnum: beamUuid,
                rules: true,
                width: 200,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 100,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { componentId, children } = record
                    return [
                        !children ? (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ) : (
                            <Fragment key="meta">
                                <TAPMateButton
                                    title="匹配"
                                    OptionsEvent={OptionsEvent}
                                    data={{
                                        actionRef,
                                        componentId,
                                        smallTitle: '匹配张拉数据',
                                        url: 'posLabTensionMatch',
                                    }}
                                />
                                <TestDetailsButton
                                    title="详情"
                                    OptionsEvent={OptionsEvent}
                                    data={{
                                        type: 'TAPDetails',
                                        title: '张拉详情',
                                        data: { type: 'LabTension', children, beamUuid },
                                    }}
                                />
                            </Fragment>
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
